Skip to content

tail: fix panic on header write error#12279

Open
gabrielhnf wants to merge 2 commits into
uutils:mainfrom
gabrielhnf:fix-tail-header-write-error
Open

tail: fix panic on header write error#12279
gabrielhnf wants to merge 2 commits into
uutils:mainfrom
gabrielhnf:fix-tail-header-write-error

Conversation

@gabrielhnf
Copy link
Copy Markdown

@gabrielhnf gabrielhnf commented May 13, 2026

Fixes #11993

Problem

When running tail on multiple files and redirecting output to a full device (e.g. /dev/full), uutils panics instead of exiting gracefully:

thread 'main' panicked at …/std/src/io/stdio.rs:1165:9:
failed printing to stdout: No space left on device (os error 28)

Instead of the correct GNU behavior:

tail: write error: No space left on device

Cause

HeaderPrinter::print used println! to write the ==> file <== headers to stdout. println! panics on write failure rather than returning a Result, so any write error (such as ENOSPC from /dev/full) caused an unhandled panic instead of a clean error message.

Fix

Replaced println! in HeaderPrinter with write_all and flush on a locked stdout, both of which return io::Result. The methods now return io::Result and propagate write errors upstream instead of panicking.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/expand/bounded-memory is now passing!
Congrats! The gnu test tests/printf/printf-surprise is now passing!

@gabrielhnf gabrielhnf force-pushed the fix-tail-header-write-error branch from b9d2a4a to 014cb8d Compare May 14, 2026 19:24
@gabrielhnf
Copy link
Copy Markdown
Author

Accidentally force-pushed the wrong commit onto the PR branch for a few minutes. I’ve restored the branch to the correct state now, sorry about the noise.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 15, 2026

Merging this PR will degrade performance by 19.55%

❌ 1 regressed benchmark
✅ 316 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory cp_recursive_deep_tree[(120, 4)] 562.5 KB 699.2 KB -19.55%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gabrielhnf:fix-tail-header-write-error (b9d2a4a) with main (6a942ba)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tail file2 file2 >/dev/full panics

1 participant